import axios from 'axios';

// axios 实例
const service = axios.create({
  baseURL: process.env.REACT_APP_AXIOS_BASE_URL,
  timeout: 5000,
})

const token = 'djaiowdjioahoigoibuaduoiu'

// 请求拦截器
service.interceptors.request.use(
  (config) => {


    config.headers['Authorization'] = 'Bearer' + token

    return config
  },
)

// 响应拦截
service.interceptors.response.use(
  (response) => {
    const { status, data, statusText } = response
    if (status >= 200 && status < 300) {
      return data
    } else {
      const error = new Error('错误' + statusText)
      return Promise.reject(error)
    }
  },
)

export default service
